/*
 * Project Name: showtao
 * File Name: VehicleModel.java
 * Class Name: VehicleModel
 *
 * Copyright 2014 showtao.com
 *
 * Licensed under the showtao.com
 *
 * http://showtao.com
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.showtao.front.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.codehaus.jackson.annotate.JsonIgnore;

@SuppressWarnings("serial")
@Entity
@Table(name = "st_vehicle_model")
public class VehicleModel extends BaseDomain {

	@Id
	@GeneratedValue
	private Long id;
	@Column(name="is_hatchback")
	private String isHatchback;
	@Column
	private String name;
	@Column(name="view_count")
	private int viewCount;
	@JsonIgnore
	@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = false)
	@JoinColumn(name = "vehicle_line_id")
	private VehicleLine line;
	@JsonIgnore
	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "model", orphanRemoval = true)
	@OrderBy("categoryNumber")
	private List<VehicleModelFeature> features;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getIsHatchback() {
		return isHatchback;
	}

	public void setIsHatchback(String isHatchback) {
		this.isHatchback = isHatchback;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public int getViewCount() {
        return viewCount;
    }

    public void setViewCount(int viewCount) {
        this.viewCount = viewCount;
    }

    public VehicleLine getLine() {
		return line;
	}

	public void setLine(VehicleLine line) {
		this.line = line;
	}

	public List<VehicleModelFeature> getFeatures() {
		return features;
	}

	public void setFeatures(List<VehicleModelFeature> features) {
		this.features = features;
	}

	@Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        } else if (!this.getClass().isInstance(obj)) {
            return false;
        }
        return new EqualsBuilder().append(id, ((VehicleModel) obj).getId()).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(id).toHashCode();
    }

}
